/*
lifer.h
offer lifer headfile.data type define,control api
designed by lunanting

-------------------------
2020-04-28 20:18:52
create file
------------------------

*/
#ifndef __LIFTER_H
#define __LIFTER_H

#include "panasonic.h"


#ifndef DRYER
#define JH  1
#endif

#ifdef DRYER
#define LIFTER_line_speed 0.1  //升降缸移动速度,m/s

#define LIFTER_ratio 1.0    //电缸减速比
#define LIFTER_pitch 0.005  //电缸螺距
#define LIFTER_part 10000   //一圈脉冲数
#define LIFTER_io_top    0  //升降缸顶部位置 io pin number

#define LIFTER_motor 1  //升降缸控制电机数，1=单控，2=双控

#define LIFTER_bottom_hight (-0.37) //升降最低高度，单位m
#define LIFTER_top_hight    (0.6)   //升降最高高度，单位m

#elif defined JH
#define LIFTER_bottom_hight (-0.37) //升降最低高度，单位m
#define LIFTER_top_hight    (0.9)   //升降最高高度，单位m

#define LIFTER_line_speed 0.1   //升降缸移动速度,m/s
#define LIFTER_high_speed 0.2   //上下刷洗时的升降速度，m/s

#define LIFTER_ratio 30    //电缸减速比
#define LIFTER_pitch 0.208  //电缸螺距 m
#define LIFTER_part 10000   //一圈脉冲数
#define LIFTER_io_top    0  //升降缸顶部位置 io pin number

#define LIFTER_motor 1  //升降缸控制电机数，1=单控，2=双控

#else
#define LIFTER_line_speed 0.1  //升降缸移动速度,m/s

#define LIFTER_ratio 1.5    //电缸减速比
#define LIFTER_pitch 0.005  //电缸螺距
#define LIFTER_part 10000   //一圈脉冲数
#define LIFTER_io_top    0  //升降缸顶部位置 io pin number

#define LIFTER_motor 2  //升降缸控制电机数，1=单控，2=双控
#endif


#define LIFTER_io_up    0   //磁力顶部 io pin number
#define LIFTER_io_down  1   //磁力底部 io pin number
#define LIFTER_io_touch 0   //磁力传感器触发状态

#define LIFTER_io_origin 10  //升降缸原点位置 io pin number
#define LIFTER_io_bottom 1  //升降缸底部位置 io pin number

#define LIFTER_io_error0  24      //驱动器0错误报警信号，正常输出0
#define LIFTER_io_error1  25     //驱动器1错误报警信号

#define LIFTER_io_left_locker   12      //左电机抱闸
#define LIFTER_io_right_locker  13      //右电机抱闸

#define LIFTER_io_left_action    18       //左升降动作
#define LIFTER_io_right_action   19       //又升降动作
#define LIFTER_io_stop  1
#define LIFTER_io_run  0

#define LIFTER_io_power_off 16   //驱动器断电
#define LIFTER_io_power_recover 7   //驱动器断电复位

/*************************data type define**************************/

//lefter motor class
typedef struct{
    u8 init;    //init state
    u8 check_zero;  //check zero state
    u8 run; //lifter run state
    u8 error;
    float dis;  //lifter dis
    float top_hight;//lifter top hight
    float bottom_hight;//lifter bottom hight
    float line_speed;   //lifter line speed
    float location;   //move location
    int encode[2]; //encode data
    int origin_encode[2];  //origin encode
    float bottom_encode;  //bottom encode
    u8 speed_block[2];  //speed block number
    PANS_handler motor[2];  //lifer motor
}LIFTER_class;




/***********************function extern***************************/
extern int xp_lifter_init(u8 port,int speed,u8 addr);  //lifter motor init
extern int xp_lifter_recover(u8 port,int speed,u8 addr);//lifter motor recover
extern int xp_lifter_change_speed(float line_speed);    //change lifter speed
extern int xp_lifter_move_support_retry(float dis,u8 speed_block,u8 retry_cnt);
extern int xp_lifter_move(float dis,u8 speed_block); //lifter move a distance
extern int xp_lifter_single_move(u8 motor,float dis,u8 speed_block);    //single motor move
extern int xp_lifter_io_touch(u8 pin,u16 slow_time);    //lifter touch io and slower motor
extern int xp_lifter_check_zero(void);  //lifter check zero
extern int xp_lifter_get_encode(u8 motor);  //get lifter motor encode

//move list task
extern int xp_lifter_move_set(float dis);   //set move task
extern void xp_lifter_move_clear(void);  //clear move task
extern int xp_lifter_moveStatus_get(void);  //get move status

extern int xp_lifter_get_speed(float line_speed);   //get lifter motor speed
extern int xp_lifter_get_pulse(float dis);  //get lifter motor pulse number
extern float xp_lifter_get_location(void);  //convert encode to location
extern int xp_lifter_check_warn(void); //check lifter motor warnning,and repair
extern int xp_lifter_stop(void);    //lifter stop
extern int xp_lifter_as_zero(void);    //set as zero point
extern void xp_lifter_io_event(u32 event);  //lifter check io event
extern float xp_lifter_location_get(void);  //get lifter location
extern float xp_lifter_get_top_hight(void);//get lifter top hight
extern int xp_lifter_relative_move(float value);    //relative move
extern int xp_lifter_set_top(char *str);    //set lifter top hight 

extern int xp_lifter_debug(char *type,char *fun,char *param);   //lifter debug



#endif
//end of the file
